package cn.istartfinancial.service.impl;

import cn.istartfinancial.entity.SysRole;
import cn.istartfinancial.mapper.SysRoleMapper;
import cn.istartfinancial.service.RoleService;
import cn.istartfinancial.util.ReType;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author zhuxiaomeng
 * @date 2017/12/19.
 * @email 154040976@qq.com
 */
@Service
public class RoleServiceImpl implements RoleService
{

    @Autowired
    private SysRoleMapper roleMapper;

    @Override
    public int deleteByPrimaryKey(String id)
    {
        return roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SysRole record)
    {
        return roleMapper.insert(record);
    }

    @Override
    public int insertSelective(SysRole record)
    {
        return roleMapper.insertSelective(record);
    }

    @Override
    public SysRole selectByPrimaryKey(String id)
    {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SysRole record)
    {
        return roleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SysRole record)
    {
        return roleMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<SysRole> selectListByPage(SysRole sysRole)
    {
        return roleMapper.select(sysRole);
    }

    @Override
    public ReType show(SysRole role, Integer page, Integer limit)
    {
        Page<SysRole> pages = PageHelper.startPage(page, limit);
        List<SysRole> roles = roleMapper.select(role);
        return new ReType(pages.getTotal(), roles);
    }

    @Override
    public String showAll(SysRole role)
    {
        return JSON.toJSONString(roleMapper.select(role));
    }
}
